package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractEntity;
import com.moyuer.bsf.domain.model.Role;
import com.moyuer.bsf.domain.model.User;

import javax.persistence.*;

/**
 * 销售单经办人
 *
 * @author: 袁首京<yuanshoujing@gmail.com>
 * 16/4/13
 */
@Entity
@Table(name = "bill_sale_handler")
public class SaleBillHandler extends AbstractEntity {

    @JSONField(serialize = false)
    @ManyToOne
    @JoinColumn(name = "bill_sale_entry_id")
    private SaleBillEntry owner;

    @JSONField(serialize = false)
    @ManyToOne
    private User handler;

    @JSONField(serialize = false)
    @ManyToOne
    private Role job; // 经手人此单所处职位

    @Transient
    private String handlerId;
    @Transient
    private String handlerName;

    @Transient
    private String handlerPicture;

    @Transient
    private String jobId;
    @Transient
    private String jobName;


    public SaleBillEntry getOwner() {
        return owner;
    }

    public void setOwner(SaleBillEntry owner) {
        this.owner = owner;
    }

    public User getHandler() {
        return handler;
    }

    public void setHandler(User handler) {
        this.handler = handler;
    }

    public Role getJob() {
        return job;
    }

    public void setJob(Role job) {
        this.job = job;
    }

    public String getHandlerId() {
        if (handlerId != null) {
            return handlerId;
        }

        if (handler != null) {
            handlerId = handler.getId();
        }

        return handlerId;
    }

    public void setHandlerId(String handlerId) {
        this.handlerId = handlerId;
    }

    public String getHandlerName() {
        if (handlerName != null) {
            return handlerName;
        }

        if (handler != null) {
            handlerName = handler.getName();
        }

        return handlerName;
    }

    public void setHandlerName(String handlerName) {
        this.handlerName = handlerName;
    }

    public String getJobId() {
        if (jobId != null) {
            return jobId;
        }

        if (job != null) {
            jobId = job.getId();
        }

        return jobId;
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }

    public String getJobName() {
        if (jobName != null) {
            return jobName;
        }

        if (job != null) {
            jobName = job.getName();
        }
        
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public String getHandlerPicture() {
        if (handlerPicture != null) {
            return handlerPicture;
        }

        if (handler != null) {
            handlerPicture = handler.getPortraitName();
        }
        return handlerPicture;
    }

    public void setHandlerPicture(String handlerPicture) {
        this.handlerPicture = handlerPicture;
    }

    //	@Override
//	public int hashCode() {
//		final int prime = 31;
//		int result = 1;
//		result = prime * result + ((handlerId == null) ? 0 : handlerId.hashCode());
//		result = prime * result + ((jobId == null) ? 0 : jobId.hashCode());
//		return result;
//	}
//
//	@Override
//	public boolean equals(Object obj) {
//		if (this == obj)
//			return true;
//		if (getClass() != obj.getClass())
//			return false;
//		SaleBillHandler other = (SaleBillHandler) obj;
//		if (handlerId == null) {
//			if (other.handlerId != null)
//				return false;
//		} else if (!handlerId.equals(other.handlerId))
//			return false;
//		if (jobId == null) {
//			if (other.jobId != null)
//				return false;
//		} else if (!jobId.equals(other.jobId))
//			return false;
//		return true;
//	}

    
    
}
